{template 'common/header'}
<style>
.field label{float:left;margin:0 !important; width:140px;}
</style>
<div class="main">
	<ul class="nav nav-tabs">
		<li><a href="{php echo $this->createWebUrl('list');}">题库列表</a></li>
		<li class="active"><a href="{php echo $this->createWebUrl('add');}">添加题目</a></li>
	</ul>
	<div class="panel panel-info">
		<div class="panel-heading">添加题目</div>
		<div class="panel-body">
			<form action="" method="post" class="form-horizontal" role="form" id="form1">
			<div class="form-group">
				<label class="col-xs-13 col-sm-2 col-md-2 col-lg-1 control-label">题目标题</label>
				<div class="col-sm-8">
					<input class="form-control" name="title" id="" type="text" value="{$item['title']}">&nbsp;&nbsp;请输入题目标题 
				</div>	
			</div>
			<div class="form-group">
				<label class="col-xs-13 col-sm-2 col-md-2 col-lg-1 control-label">听力录音</label>
				<div class="col-sm-8">
					{php echo tpl_form_field_audio('audio', $item['audio'], $options = array());}&nbsp;&nbsp;请输入题目标题 
				</div>	
			</div>
			<div class="form-group">
				<label class="col-xs-13 col-sm-2 col-md-2 col-lg-1 control-label">选项A</label>
				<div class="col-sm-5">
					<input class="form-control" name="x_a" id="" type="text" value="{$item['a']}">&nbsp;&nbsp;请输入选项A内容，如该选项为答案请选择右侧
				</div>
				<label class="col-xs-13 col-sm-2 col-md-2 col-lg-1 control-label">答案？</label>
				<div class="col-sm-3">
					<input class="form-control" name="answer" value="a" type="radio" {if $item['answer'] == 'a'}checked{/if}>
				</div>	
			</div>
			<div class="form-group">
				<label class="col-xs-13 col-sm-2 col-md-2 col-lg-1 control-label">选项B</label>
				<div class="col-sm-5">
					<input class="form-control" name="x_b" id="" type="text" value="{$item['b']}">&nbsp;&nbsp;请输入选项B内容，如该选项为答案请选择右侧
				</div>
				<label class="col-xs-13 col-sm-2 col-md-2 col-lg-1 control-label">答案？</label>
				<div class="col-sm-3">
					<input class="form-control" name="answer" value="b" type="radio" {if $item['answer'] == 'b'}checked{/if}>
				</div>	
			</div>
			<div class="form-group">
				<label class="col-xs-13 col-sm-2 col-md-2 col-lg-1 control-label">选项C</label>
				<div class="col-sm-5">
					<input class="form-control" name="x_c" id="" type="text" value="{$item['c']}">&nbsp;&nbsp;请输入选项C内容，如该选项为答案请选择右侧
				</div>
				<label class="col-xs-13 col-sm-2 col-md-2 col-lg-1 control-label">答案？</label>
				<div class="col-sm-3">
					<input class="form-control" name="answer" value="c" type="radio" {if $item['answer'] == 'c'}checked{/if}>
				</div>	
			</div>
			<div class="form-group">
				<label class="col-xs-13 col-sm-2 col-md-2 col-lg-1 control-label">选项D</label>
				<div class="col-sm-5">
					<input class="form-control" name="x_d" id="" type="text" value="{$item['d']}">&nbsp;&nbsp;请输入选项D内容，如该选项为答案请选择右侧
				</div>
				<label class="col-xs-13 col-sm-2 col-md-2 col-lg-1 control-label">答案？</label>
				<div class="col-sm-3">
					<input class="form-control" name="answer" value="d" type="radio" {if $item['answer'] == 'd'}checked{/if}>
				</div>	
			</div>
			<div class="form-group">
				<label class="col-xs-13 col-sm-2 col-md-2 col-lg-1 control-label">分值</label>
				<div class="col-sm-3">
					<input class="form-control" name="mark" id="" type="text" value="{$item['mark']}">
				</div>
				<label class="col-xs-13 col-sm-2 col-md-2 col-lg-1 control-label">难度系数</label>
				<div class="col-sm-3">
					<input class="form-control" name="hard" type="text" value="{$item['hard']}">
				</div>
					
			</div>
			<div class="form-group">
				<label class="col-xs-13 col-sm-2 col-md-2 col-lg-1 control-label">备注</label>
				<div class="col-sm-8">
					<input class="form-control" name="remark" type="text" value="{$item['remark']}">
				</div>		
			</div>
			<div class="form-group">
				<div class="col-sm-8">
					<input type="submit" name="submit" value="提交" class="btn btn-primary">
					<input type="hidden" name="token" value="{$_W['token']}" />
				</div>		
			</div>
			</form>
		</div>
	</div>
</div>
<script type="text/javascript">
	require(['jquery', 'util'], function($, u){
		$("#form1").submit(function(){
			if($(":text[name='title']").val() == '') {
				u.message('抱歉，问题名称为必填项！', '', 'error');
				return false;
			}
			if($(":text[name='x_a']").val() == '') {
				u.message('抱歉，选项A为必填项，请返回修改！', '', 'error');
				return false;
			}
			if($(":text[name='x_b']").val() == '') {
				u.message('抱歉，选项B为必填项，请返回修改！', '', 'error');
				return false;
			}
			if($(":text[name='x_c']").val() == '') {
				u.message('抱歉，选项C为必填项，请返回修改！', '', 'error');
				return false;
			}
			if(!$(":radio[name='answer']:checked").val()) {
				u.message('抱歉，答案必填项，请返回修改！', '', 'error');
				return false;
			}
			if($(":text[name='mark']").val() == '') {
				u.message('抱歉，分值为必填项，请返回修改！', '', 'error');
				return false;
			}
			if($(":text[name='mark']").val() != '') {
				var r2 = /^\+?[1-9][0-9]*$/;
				if(!r2.test($(":text[name='mark']").val())){
					u.message('抱歉，分值必须为正整数，请返回修改！', '', 'error');
					return false;
				}
			}
			if($(":text[name='hard']").val() == '') {
				u.message('抱歉，难度为必填项，请返回修改！', '', 'error');
				return false;
			}
			return true;
		});
	});
</script>
{template 'common/footer'}